package Day011_多线程1.ZuoYe;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author zhangyan
 * @date 2020/4/28 17:23
 */
public class Test7 {
    public static void main(String[] args) throws InterruptedException {

        MyThread5 mt5 = new MyThread5();
        mt5.start();

        //主线程对a变量自增100000
        for (int i = 0; i < 20000; i++) {
            MyThread5.a.getAndIncrement();
        }
        Thread.sleep(3000);
        System.out.println("a的值为:" + MyThread5.a);
    }
}

class MyThread5 extends Thread{
    static AtomicInteger a = new AtomicInteger();

    @Override
    public void run() {
        //子线程对a变量自增100000
        for (int i = 0; i < 30000; i++) {
            //a.addAndGet(1);
            a.getAndIncrement();
        }
        System.out.println("子线程执行完...");
    }
}